<?php

class admin_Model_ComentarioMapper
{
    protected $_dbTable;

    public function setDbTable($dbTable) {

        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }

        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Enlace a tabla de datos inválido');
        }

        $this->_dbTable = $dbTable;

        return $this;
    }

    public function getDbTable() {

        if (null === $this->_dbTable) {
            $this->setDbTable('admin_Model_DbTable_Comentario');
        }

        return $this->_dbTable;
    }

    public function obtenerTodos($limite = 0) {

        $select = $this->getDbTable()->select();
        $select->order('fecha desc');

        $limite = (int) $limite;

        if($limite){
         $select->limit($limite);
        }

        return $this->getDbTable()->fetchAll($select);

    }

    public function eliminar($id) {

        $id = (int) $id;
        $articulo = $this->getDbTable()->find($id)->current();

        if ($articulo !== null) {
            $articulo->delete();
        }
    }


}

